import { defHttp } from '../http'
import type { CommonAPI } from '../model/_utils'

// 获取域名列表
export const domainListApi: CommonAPI<'/v1/domain', 'get'> = params =>
  defHttp.get('/domain', { params })

// 新增域名
export const addDomainApi: CommonAPI<'/v1/domain', 'post'> = data =>
  defHttp.post('/domain', { data })

// 删除域名
export const deleteDomainApi: CommonAPI<'/v1/domain/{id}', 'delete'> = params =>
  defHttp.delete(`/domain/${params.id}`)

// 修改域名
export const editDomainApi: CommonAPI<'/v1/domain/{id}', 'put'> = data =>
  defHttp.put(`/domain/${data.id}`, { data })

// 修改域名dns服务器
export const editDomainDnsApi: CommonAPI<'/v1/domain/{id}/ns', 'put'> = data =>
  defHttp.put(`/domain/${data.id}/ns`, { data })

// 获取管理员域名组列表
export const domainGroupListApi: CommonAPI<
  '/v1/admin_domain_group',
  'get'
> = params => defHttp.get('/admin_domain_group', { params })

// 新增管理员域名组
export const postDomainGroupApi: CommonAPI<
  '/v1/admin_domain_group',
  'post'
> = data => defHttp.post('/admin_domain_group', { data })

// 修改管理员域名组
export const putDomainGroupApi: CommonAPI<
  '/v1/admin_domain_group/{id}',
  'put'
> = data => defHttp.put(`/admin_domain_group/${data.id}`, { data })

// 删除管理员域名组
export const deleteDomainGroupApi: CommonAPI<
  '/v1/admin_domain_group/{id}',
  'delete'
> = params => defHttp.delete(`/admin_domain_group/${params.id}`)

// 加入域名到管理员组
export const joinDomainGroupApi: CommonAPI<
  '/v1/admin_domain_group/{id}/domains',
  'put'
> = data => defHttp.put(`/admin_domain_group/${data.id}/domains`, { data })

// 删除管理员域名组
export const deleteDomainGroupsApi: CommonAPI<
  '/v1/admin_domain_groups',
  'delete'
> = data => defHttp.delete('/admin_domain_groups', { data })

// 获取域名解析记录列表
export const domainRecordListApi: CommonAPI<'/v1/rr', 'get'> = params =>
  defHttp.get('/rr', {
    params
  })

// 新增域名解析记录
export const postDomainRecordApi: CommonAPI<'/v1/rr', 'post'> = data =>
  defHttp.post('/rr', { data })

// 修改域名解析记录
export const putDomainRecordApi: CommonAPI<'/v1/rr/{id}', 'put'> = data =>
  defHttp.put(`/rr/${data.id}`, { data })

// 删除域名解析记录
export const deleteDomainRecordApi: CommonAPI<
  '/v1/rr/{id}',
  'delete'
> = params => defHttp.delete(`/rr/${params.id}`)

/**批量添加域名 */
export const addBatchDomainApi: CommonAPI<'/v1/domains/batch', 'post'> = data =>
  defHttp.post('/domains/batch', { data })

// 批量添加记录
export const addBatchRecordApi: CommonAPI<'/v1/rrs/batch', 'post'> = data =>
  defHttp.post('/rrs/batch', { data })

/**批量添加记录2 */
export const addBatchRecord2Api: CommonAPI<
  '/v1/rrs/batch_line',
  'post'
> = data => defHttp.post('/rrs/batch_line', { data })

// 批量修改记录
export const updateBatchRecordApi: CommonAPI<'/v1/rrs/batch', 'put'> = data =>
  defHttp.put('/rrs/batch', { data })

// 批量删除记录
export const deleteBatchRecordApi: CommonAPI<
  '/v1/rrs/batch',
  'delete'
> = data => defHttp.delete('/rrs/batch', { data })
